package com.itheima.reggie.controller;


import com.itheima.reggie.common.OssTemplate;
import com.itheima.reggie.common.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartResolver;

import java.io.IOException;

@RestController
public class FileController {

    @Autowired
    private OssTemplate ossTemplate;

    @PostMapping("/common/upload")
    public ResultInfo upload(MultipartFile file) throws IOException {
        String url = ossTemplate.upload(file.getOriginalFilename(), file.getInputStream());
        return ResultInfo.success(url);
    }
}
